<?php
define('ROOT_PATH', '/var/www/html/new/d');
include 'common/autoload.php';
include 'common/header.html';
include 'common/left.html';
include 'common/page.php';
include 'common/area.inc.php';
include 'common/Prod_Common.php';
use \pft\Prod\Product;
use \pft\Member\MemberAccount;

$lvl_limit = array(0, 2, 6, 9);
if(!in_array($_SESSION['dtype'], $lvl_limit)) {
    exit('不合法的身份！');
}
if ($_SESSION['dtype']==6) {
    if(\pft\Member\MemberAccount::GetMemType($_SESSION['sid'])!=0) {
        exit('您的上级不是供应商身份，无法发布产品。');
    }
}

if(empty($_SESSION['com_type'])) {
    $sqlGetComType = "SELECT com_type FROM pft_member_extinfo WHERE fid={$_SESSION['memberID']}";
    $GLOBALS['le']->query($sqlGetComType);
    $GLOBALS['le']->fetch_assoc();
    $_SESSION['com_type'] = $GLOBALS['le']->f('com_type');
}
$currentPage =$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize    =$_REQUEST["pageSize"]?$_REQUEST["pageSize"]:10;
$offset      =($currentPage-1)*$pageSize;
if(!isset($status)) {
    $status = isset($_GET['s']) ? abs($_GET['s']) : 1;
}
$page_title = $status == 2 ? '仓库中产品' : '自供应产品';
if(!is_numeric($status)) {
    exit('非法的参数！');
}

//print_r($_SESSION);

$ticketOption = array(
    'apply_limit'=> $status,
);
if($_SESSION['dtype']==0) {
    $params['applyer'] = $_SESSION['memberID'];
}
elseif($_SESSION['dtype']==6) {
    $params['applyer'] = $_SESSION['sid'];
}
elseif($_SESSION['dtype']==2) {
    $mem = new MemberAccount($GLOBALS['le']);
    $params['salerid'] = $mem->getAccountById($_SESSION['memberID']);
}
if(!empty($_GET['s_input'])) {
    $p_title = trim(strip_tags($_GET['s_input']));
    $params['title'] = addslashes($p_title);
}

if (!empty($_GET['apply_did']) && $_SESSION['dtype']==9) {
    $params['applyer'] = intval($_GET['apply_did']);
}

if (is_numeric($_GET['d_province']) && $_GET['d_province']>0) {
    $params['area'] = $_GET['d_province'] . '|';
    if (is_numeric($_GET['d_city']) && $_GET['d_city']>0) {
        $params['area'] .= $_GET['d_city'];
    }
}

$params['status'] = $status;
$params['limit']  = $offset;
$params['offset'] = $pageSize;

if(!empty($_GET['s_title'])) {
    $params['title'] = safetxt($_GET['s_title']);
}
if(!empty($_GET['p_type']) && $_GET['p_type']) {
    $params['p_type'] = safetxt($_GET['p_type']);
}
if(ctype_digit($_GET['terminal'])) {
    $params['terminal'] = $_GET['terminal'];
}
if($_REQUEST['supplier']){
    $params['supplier'] = $_REQUEST['supplier'];
}
$soap = SoapInit::GetSoapInside();
$obj = new Product($GLOBALS['le'], $soap);
//print_r($params);
$data = $obj->GetProductsList($params, $ticketOption);
//print_r($data);
//exit;
//$ptype_count = array();
$add_list = array('A'=>'票类','B'=>'票类','C'=>'客房','D'=>'商品','F'=>'套票');
$sta_list = array('0'=>'<span class="red">[未审核]</span>','','<span class="red">[被拒绝]</span>');
$debug    = false;

if($_GET['cgp'] && $_GET['cgp']=='225800') {
//    $hideProducts = $obj->GetEmptyProduct($_SESSION['memberID']);
    print_r($data);
}

//TODO::获取会员数据
$memberNames = include dirname(__FILE__) . '/module/link_product/Member.cache.php';
// 仓库中的产品
if($status==2) {

    // 获取没有添加门票的产品
    //TODO::这里有个bug
    $hideProducts = $obj->GetEmptyProduct($_SESSION['memberID']);
    if (is_array($hideProducts) && count($hideProducts)) {
        $data['lands'] = is_array($data['lands']) ? array_merge($data['lands'], $hideProducts) : $hideProducts;
    }
    // 加载套票系统下架提示
    $packageMsg = include '/var/www/html/new/d/module/link_product/tarMessage.php';
}
//print_r($data['lands']);
// admin 账号
if($_SESSION['memberID']==1){
    include 'getDistors.php';
	$DistorsNames = getAllMember($GLOBALS['le']);
}
include TPLPATH.'prodlists_sync.tpl';
include 'common/footer.html';

?>